/*
 * Copyright (c) 2007 by Chances.
 * $CVSHeader: IPTV_VAS_Release1/src/commons/chances/vas/commons/utils/CodeUtils.java,v 1.1 2008/04/17 02:23:14 chenxx Exp $
 * $Author: chenxx $
 * $Date: 2008/04/17 02:23:14 $
 * $Revision: 1.1 $
 */
package chances.commons.crypto;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author <a href="mailto:zhangxb@chances.com.cn">zhangxb</a>
 */
public class DateUtils {
    private static final Logger LOG = LoggerFactory.getLogger(DateUtils.class);

    static DateTimeFormatter yyyyMMddHHmmss = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    static DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static void main(String[] args) throws Exception {
        stringToDate("2013-1-11 11:11:11");
    }

    public static String dateToYYYYMMDD(Date date) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.format(date);
        } catch (Exception e) {
            LOG.error(e.toString(), e);
            return null;
        }
        // LocalDateTime localDateTime = LocalDateTime.parse(dateStr,
        // yyyyMMddHHmmss);
        // ZoneId zone = ZoneId.systemDefault();
        // Instant instant = localDateTime.atZone(zone).toInstant();
        // Date date = Date.from(instant);
        // return date;
    }

    public static Date stringToDate(String dateStr) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(dateStr);
        // LocalDateTime localDateTime = LocalDateTime.parse(dateStr,
        // yyyyMMddHHmmss);
        // ZoneId zone = ZoneId.systemDefault();
        // Instant instant = localDateTime.atZone(zone).toInstant();
        // Date date = Date.from(instant);
        // return date;
    }

}
